<?php

!defined('BASE_PATH')&&die('forbidden');

class core_auth_signbase{
	
	private static function _create_signature($string, $start, $end, $secret_salt){
		
		return md5($string . $start . $end . $secret_salt);
		
	}
	
	public static function add_signature($string, $start, $end, $secret_salt){
		
		return self::_create_signature($string, $start, $end, $secret_salt) . $start . $end . $string;
		
	}
	
	public static function remove_signature($string, $secret_salt){
		
		$now = time();
		$signature = substr($string, 0, 32);
		$start = substr($string, 32, 10);
		$end = substr($string, 42, 10);
		$string = substr($string, 52);
		
		if ($signature != self::_create_signature($string, $start, $end, $secret_salt)) {
			return false;
		}
		
		if ($start == $end || ($now>$start && $now<=$end)) {
			return $string;
		}else {
			return false;
		}
		
	}
	
}

?>